# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=kibana
pkgver=6.4.1
pkgrel=0
pkgdesc="Visualize Elasticsearch data and navigate the Elastic Stack"
url="https://www.elastic.co/products/kibana"
arch="x86_64"
license="Apache-2.0"
depends="nodejs"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
pkgusers="kibana"
pkggroups="kibana"
options="!check" # no test suite
source="https://artifacts.elastic.co/downloads/kibana/kibana-oss-$pkgver-linux-x86_64.tar.gz
	kibana.initd
	default_config.patch
	"
builddir="$srcdir"/$pkgname-$pkgver-linux-x86_64

build() {
	return 0
}

package() {
	cd "$builddir"
	install -m755 -d \
		"$pkgdir"/usr/share/webapps/$pkgname \
		"$pkgdir"/var/lib/$pkgname \
		"$pkgdir"/usr/share/doc/$pkgname

	# move config into /etc
	install -m755 -d "$pkgdir"/etc/$pkgname
	install -m644 -o $pkgusers -g $pkggroups config/kibana.yml "$pkgdir"/etc/$pkgname/kibana.yml
	rm config/kibana.yml && rmdir config

	# move data into /var
	install -m755 -o $pkgusers -g $pkggroups -d "$pkgdir"/var/lib/$pkgname/data
	rmdir data

	# remove ELF compiled against GLIBC
	rm node_modules/clipboardy/fallbacks/linux/xsel

	# move docs into subpkg
	mv *.txt "$pkgdir"/usr/share/doc/$pkgname

	# use system nodejs
	rm -rf node

	# everything else in webapps
	mv * "$pkgdir"/usr/share/webapps/$pkgname

	install -m755 -D "$srcdir"/$pkgname.initd $pkgdir/etc/init.d/$pkgname
}

sha512sums="54c4f997037a7d3ff8820abfef72914674d733a05906bf692bb33a8c49f61d7d0e362eefc9ef522e848bff354ebfeade507aecdb5e9652bcedb1d2b9167daeb0  kibana-oss-6.4.1-linux-x86_64.tar.gz
a6988b51ad758bce6c31aa90b905f833c7b641dec6b63a9da928c328b3da42a69bb855ecdbd22c15e035a20c6f28f90ddd88d85c6890acd58bef7608be2c25e8  kibana.initd
fae5536d02f6bb90d2e5930532e41b8327790eb83e412028b25eb0c7bd44d8fa38edd66fa9f4017d86819baba929e56dbc49bdb1dcbdea16f3447daa457514f4  default_config.patch"
